package com.zzg.algorithm.floyd;

import com.zzg.algorithm.floyd.entity.Graph;

/**
 * @Author zhengzg
 * @Date 2022-10-10
 * @Version v1.0
 * 弗洛伊德算法：最短路径问题
 * 1) 胜利乡有 7 个村庄(A, B, C, D, E, F, G)
 * 2) 各个村庄的距离用边线表示(权) ，比如 A – B 距离 5 公里
 * 3) 问：如何计算出各村庄到 其它各村庄的最短距离?
 */
public class FloydAlgorithm {
    public static void main(String[] args) {
        char[] vertex = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
        //创建邻接矩阵
        int[][] matrix = new int[vertex.length][vertex.length];
        final int N = 65535;
        matrix[0] = new int[] { 0, 5, 7, N, N, N, 2 };
        matrix[1] = new int[] { 5, 0, N, 9, N, N, 3 };
        matrix[2] = new int[] { 7, N, 0, N, 8, N, N };
        matrix[3] = new int[] { N, 9, N, 0, N, 4, N };
        matrix[4] = new int[] { N, N, 8, N, 0, 5, 4 };
        matrix[5] = new int[] { N, N, N, 4, 5, 0, 6 };
        matrix[6] = new int[] { 2, 3, N, N, 4, 6, 0 };

        //创建 Graph 对象
        Graph graph = new Graph(vertex.length, matrix, vertex);
        //调用弗洛伊德算法
        graph.floyd();
        graph.show();
    }
}
